<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;

/**
 * @ApiResource()
 * @ORM\Entity(repositoryClass="App\Repository\OrdersRepository")
 */
class Orders
{
    /**
     * @Groups({"order"})
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @Groups({"order"})
     * @ORM\ManyToOne(targetEntity="App\Entity\User")
     * @ORM\JoinColumn(nullable=false)
     */
    private $buyer;

    /**
     * @Groups({"order"})
     * @ORM\ManyToOne(targetEntity="App\Entity\User")
     * @ORM\JoinColumn(nullable=true)
     */
    private $seller;

    /**
     * @Groups({"order"})
     * @ORM\ManyToOne(targetEntity="App\Entity\UserAddress")
     * @ORM\JoinColumn(nullable=true)
     */
    private $address;

    /**
     * @Groups({"order"})
     * @ORM\ManyToOne(targetEntity="App\Entity\UserContact")
     * @ORM\JoinColumn(nullable=true)
     */
    private $contact;

    /**
     * @Groups({"order"})
     * @ORM\Column(type="string", length=255)
     */
    private $sn;

    /**
     * @Groups({"order"})
     * @ORM\Column(type="datetime")
     */
    private $createAt;

    /**
     * @Groups({"order"})
     * @ORM\Column(type="float")
     */
    private $payTotal;

    /**
     * @Groups({"order"})
     * @ORM\Column(type="float")
     */
    private $payReal;

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $payAt;

    /**
     * @ORM\Column(type="smallint")
     */
    private $payType;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $paCode;

    /**
     * @ORM\Column(type="json", nullable=true)
     */
    private $sales = [];

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $settleAt;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $settleMessage;

    /**
     * @Groups({"order"})
     * @ORM\Column(type="smallint")
     */
    private $status;

    /**
     * @Groups({"order"})
     * @ORM\OneToMany(targetEntity="App\Entity\OrderPackage", mappedBy="orders", orphanRemoval=true)
     */
    private $package;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Appeal", mappedBy="orders")
     */
    private $appeals;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Comment", mappedBy="what")
     */
    private $comments;

    /**
     * 订单类型
     * 1：任务订单
     * 2：服务订单
     * @ORM\Column(type="smallint", nullable=true)
     */
    private $type;

    public function __construct()
    {
        $this->package = new ArrayCollection();
        $this->appeals = new ArrayCollection();
        $this->comments = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getBuyer(): ?User
    {
        return $this->buyer;
    }

    public function setBuyer(?User $buyer): self
    {
        $this->buyer = $buyer;

        return $this;
    }

    public function getSeller(): ?User
    {
        return $this->seller;
    }

    public function setSeller(?User $seller): self
    {
        $this->seller = $seller;

        return $this;
    }

    public function getAddress(): ?UserAddress
    {
        return $this->address;
    }

    public function setAddress(?UserAddress $address): self
    {
        $this->address = $address;

        return $this;
    }

    public function getContact(): ?UserContact
    {
        return $this->contact;
    }

    public function setContact(?UserContact $contact): self
    {
        $this->contact = $contact;

        return $this;
    }

    public function getSn(): ?string
    {
        return $this->sn;
    }

    public function setSn(string $sn): self
    {
        $this->sn = $sn;

        return $this;
    }

    public function getCreateAt(): ?\DateTimeInterface
    {
        return $this->createAt;
    }

    public function setCreateAt(\DateTimeInterface $createAt): self
    {
        $this->createAt = $createAt;

        return $this;
    }

    public function getPayTotal(): ?float
    {
        return $this->payTotal;
    }

    public function setPayTotal(float $payTotal): self
    {
        $this->payTotal = $payTotal;

        return $this;
    }

    public function getPayReal(): ?float
    {
        return $this->payReal;
    }

    public function setPayReal(float $payReal): self
    {
        $this->payReal = $payReal;

        return $this;
    }

    public function getPayAt(): ?\DateTimeInterface
    {
        return $this->payAt;
    }

    public function setPayAt(?\DateTimeInterface $payAt): self
    {
        $this->payAt = $payAt;

        return $this;
    }

    public function getPayType(): ?int
    {
        return $this->payType;
    }

    public function setPayType(int $payType): self
    {
        $this->payType = $payType;

        return $this;
    }

    public function getPaCode(): ?string
    {
        return $this->paCode;
    }

    public function setPaCode(string $paCode): self
    {
        $this->paCode = $paCode;

        return $this;
    }

    public function getSales(): ?array
    {
        return $this->sales;
    }

    public function setSales(?array $sales): self
    {
        $this->sales = $sales;

        return $this;
    }

    public function getSettleAt(): ?\DateTimeInterface
    {
        return $this->settleAt;
    }

    public function setSettleAt(?\DateTimeInterface $settleAt): self
    {
        $this->settleAt = $settleAt;

        return $this;
    }

    public function getSettleMessage(): ?string
    {
        return $this->settleMessage;
    }

    public function setSettleMessage(?string $settleMessage): self
    {
        $this->settleMessage = $settleMessage;

        return $this;
    }

    public function getStatus(): ?int
    {
        return $this->status;
    }

    public function setStatus(int $status): self
    {
        $this->status = $status;

        return $this;
    }

    /**
     * @return Collection|OrderPackage[]
     */
    public function getPackage(): Collection
    {
        return $this->package;
    }

    public function addPackage(OrderPackage $package): self
    {
        if (!$this->package->contains($package)) {
            $this->package[] = $package;
            $package->setOrders($this);
        }

        return $this;
    }

    public function removePackage(OrderPackage $package): self
    {
        if ($this->package->contains($package)) {
            $this->package->removeElement($package);
            // set the owning side to null (unless already changed)
            if ($package->getOrders() === $this) {
                $package->setOrders(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|Appeal[]
     */
    public function getAppeals(): Collection
    {
        return $this->appeals;
    }

    public function addAppeal(Appeal $appeal): self
    {
        if (!$this->appeals->contains($appeal)) {
            $this->appeals[] = $appeal;
            $appeal->setOrders($this);
        }

        return $this;
    }

    public function removeAppeal(Appeal $appeal): self
    {
        if ($this->appeals->contains($appeal)) {
            $this->appeals->removeElement($appeal);
            // set the owning side to null (unless already changed)
            if ($appeal->getOrders() === $this) {
                $appeal->setOrders(null);
            }
        }

        return $this;
    }

    /**
     * @return Collection|Comment[]
     */
    public function getComments(): Collection
    {
        return $this->comments;
    }

    public function addComment(Comment $comment): self
    {
        if (!$this->comments->contains($comment)) {
            $this->comments[] = $comment;
            $comment->setWhat($this);
        }

        return $this;
    }

    public function removeComment(Comment $comment): self
    {
        if ($this->comments->contains($comment)) {
            $this->comments->removeElement($comment);
            // set the owning side to null (unless already changed)
            if ($comment->getWhat() === $this) {
                $comment->setWhat(null);
            }
        }

        return $this;
    }

    public function getType(): ?int
    {
        return $this->type;
    }

    public function setType(?int $type): self
    {
        $this->type = $type;

        return $this;
    }
}
